package com.sky.mapper;

import com.sky.entity.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    @Insert("insert into employee (id,username,password,name,phone,sex,id_number,status,create_time,update_time,create_user,update_user) values (#{id},#{username},#{password},#{name},#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    int addEmployee(Employee employee);

    @Select("select * from employee where id = #{id}")
    Employee selectEmployeeById(Long id);

    List<Employee> findAllEmployee(String name);

    @Select("select * from employee where id=#{empId} and password=#{oldPassword}")
    Employee checkOldPassword(Long empId, String oldPassword);

    @Update("update employee set password = #{newPassword} where id = #{empId}")
    void updatePasswordById(Long empId, String newPassword);

//    @Update("update employee set status=#{status} where id = #{id}")
//    int changeStatusByID(Integer status, Long id);

//    @Update("update employee set name=#{name},phone=#{phone},sex=#{sex},id_number=#{idNumber},update_time=#{updateTime},update_user=#{updateUser} where username=#{username}")
//    int editEmployee(Employee employee);

    void update(Employee employee);
}
